#include <stdio.h>
#include <stdarg.h>

static FILE *log_fp=NULL;
static char file_name[128] = {0};

void sys_log_open(char* machine_id)
{

	sprintf(file_name,"./%s",machine_id);
//	remove(file);
//	log_fp = fopen(file, "w+");	
   	log_fp = fopen(file_name, "at+");	
}

void sys_log_remove()
{
    sys_log_close();
    remove(file_name);
}

void sys_log_close()
{
	if(log_fp) log_fp = fclose(log_fp);
	log_fp = NULL;
}

void sys_log_print(const char *file_name ,const int file_line,const char *funciton_name, char* message, ...)
{
	va_list variable_list;

	if(!log_fp) {
		printf("fp error\n");
		return;
	}

	va_start(variable_list, message);
	fprintf(log_fp,"[%s:%d][%s]",file_name,file_line,funciton_name);
	vfprintf(log_fp,message, variable_list);
	fprintf(log_fp,"\n");
	va_end(variable_list);
	return;
}
